<!--
 * @Author: 路漫漫
 * @Date: 2022-11-08 15:52:03
 * @项目描述: 
 * @Description: 花有重开日，人无再少年
-->
<template>
  <el-image
    :style="`width: ${realWidth}; height: ${realHeight}`"
    :src="realSrc"
    fit="cover"
    :preview-src-list="srcList"
    @click="(srcList = []), srcList.push(realSrc)"
  >
    <div slot="error" class="image-slot">
      <i class="el-icon-picture-outline"></i></div
  ></el-image>
</template>

<script>
export default {
  name: "",
  components: {},
  props: {
    src: {
      type: String,
      default: "",
    },
    height: {
      type: [Number, String],
      default: "100%",
    },
    width: {
      type: [Number, String],
      default: "100%",
    },
  },
  data() {
    return {
      srcList: [
        "https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
      ],
    };
  },
  computed: {
    realSrc() {
      if (!this.src) {
        return;
      }
      let real_src = this.src.split(",")[0];
      if (this.isExternal(real_src)) {
        return real_src;
      }
      return this.$img + real_src;
    },
    realWidth() {
      return typeof this.width == "string" ? this.width : `${this.width}px`;
    },
    realHeight() {
      return typeof this.height == "string" ? this.height : `${this.height}px`;
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    isExternal(path) {
      return /^(https?:|mailto:|tel:)/.test(path);
    },
  },
};
</script>

<style scoped lang='scss'>
.el-image {
  border-radius: 5px;
  background-color: #ebeef5;
  box-shadow: 0 0 5px 1px #ccc;
  ::v-deep .el-image__inner {
    transition: all 0.3s;
    cursor: pointer;
    &:hover {
      transform: scale(1.2);
    }
  }
  ::v-deep .image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    color: #909399;
    font-size: 30px;
  }
  ::v-deep .el-image-viewer__close {
    color: #fff;
  }
}
</style>

